<?php
	if(!isset($_REQUEST['flag']))
	{
		$send=0;
	}
	else if($_REQUEST['flag']==1)
	{
		$send=1;
		ob_start();
	}
 
 class phpReportGenerator
{
    var $mysql_resource;
	var $header;
	var $foolter;
    var $fields = array();
	var $cellpad;
	var $cellspace;
	var $border;
	var $width;
	var $modified_width;
	var $header_color;
	var $header_textcolor;
	var $header_alignment;
	var $body_color;
	var $body_textcolor;
	var $body_alignment;
	var $surrounded;
	var $outstanding_amt;
	var $message_output;
	
	
	function PrintInvoiceNumber()
	{
	 if ($_REQUEST['reporttype']=="Invoice")
		{
			return "&nbsp;&nbsp;Invoice No:   ".$_REQUEST['invoicenumber']; 
		}
	else 
		{
			return "&nbsp;&nbsp;Credit Note No:   ".$_REQUEST['invoicenumber']; 
		} 
	}
	
	
	function PrintInvoiceDate()
	{
		
	 if ($_REQUEST['reporttype']=="Invoice")
		{
		return "&nbsp;&nbsp;Invoice Date:   ".$_REQUEST['invoicedate']; 
		}
			else 
		{
		return "&nbsp;&nbsp;Credit Date:   ".$_REQUEST['invoicedate']; 
		} 
				
	}
	
	function GetCustomerAddress()
	{
		 $sqlb = "SELECT prefx, custdesc,address, city from customermast where custid=".$_REQUEST['custid'];
		 $result = mysql_query($sqlb);
		 if (!$result) {
			 echo "Could not successfully run query ($sql) from DB: " . mysql_error();
			 exit;
		 }
		
		 $row = mysql_fetch_row($result);
         $custprefx = $row[0];
         $custdesc = $row[1];
		 $custaddr = $row[2];
		 $custcity = $row[3];
		 
		return '&nbsp;'.$custprefx.'<br>'.' &nbsp;&nbsp;'.$custdesc.'<br>'.' &nbsp;&nbsp;'.$custaddr.'<br>'.' &nbsp;&nbsp;'.$custcity; 
	}
		
	function generateReport($message)
	{
	$val=0;
	$emailbody=array();
	$emailbody[$val++]=$message;
	
	
		$this->border = (empty($this->border))?"1":$this->border;
		$this->cellpad = (empty($this->cellpad))?"1":$this->cellpad;
		$this->cellspace = (empty($this->cellspace))?"0":$this->cellspace;
		$this->width = (empty($this->width))?"100%":$this->width;
		$this->header_color = (empty($this->header_color))?"#FFFFFF":$this->header_color;
		$this->header_textcolor = (empty($this->header_textcolor))?"#000000":$this->header_textcolor;		
		$this->header_alignment = (empty($this->header_alignment))?"Center":$this->header_alignment;
		$this->body_color = (empty($this->body_color))?"#FFFFFF":$this->body_color;
		$this->body_textcolor = (empty($this->body_textcolor))?"#000000":$this->body_textcolor;
		$this->body_alignment = (empty($this->body_alignment))?"Right":$this->body_alignment;
		$this->surrounded = (empty($this->surrounded))?false:true;
		$this->modified_width = ($this->surrounded==true)?"100%":$this->width;
		
		/*
		* Lets calculate how many fields are there in supplied resource
		* and store their name in $this->fields[] array
		*/
		
		$field_count = mysql_num_fields($this->mysql_resource);
		$i = 0; 
		
		while ($i < $field_count)
		{
			$field = mysql_fetch_field($this->mysql_resource);
			$this->fields[$i] = $field->name;
			$this->fields[$i][0] = strtoupper($this->fields[$i][0]);
			$i++;
		}
				
		
		//Now fill the table with data
		while ($rows = mysql_fetch_row($this->mysql_resource))
		{
		     $o = strpos($rows[3],'otal Outstanding');
			 if($o > 0)
             {
		    	$emailbody[$val++]= "<tr borderalign = ".$this->body_alignment." bgcolor = '#d4d4d4'>"; 			
			 }
			 else
			 {
			    $emailbody[$val++]=  "<tr  align=".$this->body_alignment." bgcolor = '#ffffff'>"; 	
			 }
			 
			
			for ($i = 0; $i < $field_count; $i++)
			{
			
			//if($i<2) continue; //skip printing 1st and 2nd col
				$len = strlen($rows[$i]);
				if($len =1) 
				  $desc = $rows[$i];
				else
				  $desc = '';
				
                $len1 = strlen($rows[$i]);
    			if($len1 !=1) 
				  $desc1  = $rows[$i];
				else
				  $desc1 = '';
				
				$this->outstanding_amt =$_REQUEST['invoiceamount'];

				// only credit entries for Credit Note 
				// only Debit entries for Invoice
				if(
					(($_REQUEST['reporttype']=="Invoice") && $rows[7]=="D") ||
					(($_REQUEST['reporttype']=="CreditNote") && $rows[7]=="C") 
				)
				{
				
					if($i!=7) {
						if($i==6) 
						{
							$emailbody[$val++]="<TD align='center'  style='border-left:1px solid #000001;border-right:1px solid #000001;border-bottom:1px solid #000001;padding:0.03in'> <P LANG='en-US' CLASS='western' %s><FONT FACE='Arial, serif' SIZE=1>".$desc."</FONT></P></TD>";
							
						}
						  else
						 {
							$emailbody[$val++]="<TD  align='center' style='border-left:1px solid #000001;border-right:none; border-bottom:1px solid #000001;padding:0.03in'> <P LANG='en-US' CLASS='western' %s><FONT FACE='Arial, serif' SIZE=1>".$desc."</FONT></P></TD>"; 
							
						 }
					}
				}
			}
			$emailbody[$val++]= "</tr>";
		}
	  
	  for($i=0;$i<=$val;$i++)
		{
		$r.=$emailbody[$i];
		}
		echo $r;
		
		return $r."</table>";
	}
  }

//if($send==0)
//{
if($_REQUEST['reporttype']=='Invoice')
$reportname = 'Invoice';
if($_REQUEST['reporttype']=='CreditNote')
$reportname = 'Credit Note';	


$message='<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"></head>
 
<body>
  <div link="#0000ff" dir="LTR" lang="en-IN">
  <table cellpadding="0" cellspacing="0" width="730">
 <tbody>
   <tr>
	<td style="border-top:none;border-bottom:none;border-left:none;border-right:none;padding:0in;line-height:100%;margin-bottom:none" align="RIGHT"> 
	<img align="LEFT" src="http://shreecomm.com/invoiceapp/prod/shreelogo.png" alt="name" width="100" height="100" />
    <p align="RIGHT"><font face="Arial, serif"> <font style="font-size:9pt" size="1">
			<b><font color="red" style="font-size:12pt" font-family= "TT18o00"> Shree Communications&nbsp;</b> </font><br>
				2, Ganesh Darshan, LBS Marg,&nbsp;<br> 
				Mulund Check Naka, Mulund (W)&nbsp;<br>
				Mumbai-400080, India&nbsp; <br>
				Tel : +91 022-21641631 / 21649516 &nbsp; <br>
                Email: mail@shreecomm.com <br>
</p>
	</td>
 </tr>
	
	<tr>
	  <td style="border-left:none;border-right:none;border-bottom:1px solid #000001;padding:0in" align="RIGHT"> 
			
		<p align="RIGHT"><font face="Arial, serif"><font style="font-size:9pt" size="1"><br>
           <b><font style="font-size:11pt" style="font-family:Helvetica-Bold" color="#17375D">NEFT/RTGS Details&nbsp;</b></font><br> 
            Bank: Axis Bank: LBS Marg, Mulund West&nbsp; <br>
		    Account No: 508010300000037&nbsp; <br>
	        IFSC Code: UTIB0000508&nbsp; <br></font> </font></p>
	  </td>
	</tr>
     <tr>
		<td style="border-left:1px solid #000001;border-right:1px solid #000001;border-bottom:1px solid #000001;padding:0in" align="RIGHT"> 
		<font style="font-size:8pt" face="Arial, serif" size="1">
		<p align="CENTER"><font face="Arial, serif"><font style="font-size:13pt" color="#17375D" size="3"><b>'.$reportname.'</b> </font> </font></p>
		</font></td>
	</tr>
 </tbody>
</table>

 <table cellpadding="0" cellspacing="0" width="730">
  <colgroup>
     <col width="150">
     <col width="200">
  </colgroup>
 
	 <tbody>
     <tr><td style="border-left:1px solid #000001;border-right:1px solid #000001;padding:0in" align="LEFT" width="270">
  	     <p><font face="Arial, serif"><font style="font-size:8pt" size="1">&nbsp;';
		 
	     	include_once("conn.php");
	    	$prg = new phpReportGenerator();
	    	$message .= $prg->GetCustomerAddress();
	     
		 $message .='</font></font></p> 
		 </td>
   <td style="border-right:1px solid #000001;padding:0in" width="158">
	<p><font face="Arial, serif"><font style="font-size:8pt" size="1"><br><b>&nbsp;&nbsp;&nbsp;&nbsp;Details:</b></font></font></p>
	 <font face="Arial, serif"><font style="font-size:8pt" size="1"> ';
	
	 	include_once("conn.php");
		$prg = new phpReportGenerator();
		$message .=$prg->PrintInvoiceNumber();
	 
	 $message .='</font></font><br>
	 
	 <font face="Arial, serif"><font style="font-size:8pt" size="1"> ';
	
	 	include_once("conn.php");
		$prg = new phpReportGenerator();
		$message .=$prg->PrintInvoiceDate();
	 
	 $message .='</font></font><br>
	 
    </td>
    </tr>
    </tbody>
</table>

	  <table cellpadding="0" cellspacing="0" width="730">
		 <colgroup>
          	 <col width="185">
			 <col width="95"> 
             <col width="98">
			 <col width="75">
			 <col width="85">
			 <col width="80">
			 <col width="112">
		</colgroup>
		<tbody>
		  <tr>
			<td style="border-top:1px solid #000001;border-bottom:1px solid #000001;border-left:1px solid #000001;border-right:none;padding:0in">
    		 <p align="CENTER"><font face="Arial, serif"><font style="font-size:8pt" size="1"><b>&nbsp;&nbsp;Pax Name</b></font></font></p>
			</td>
			
			<td style="border-top:1px solid #000001;border-bottom:1px solid #000001;border-left:1px solid #000001;border-right:none;padding:0in">
			 <p align="CENTER"><font face="Arial, serif"><font style="font-size:8pt" size="1"><b>&nbsp;&nbsp;Sector</b></font></font></p>
			</td>

			<td style="border-top:1px solid #000001;border-bottom:1px solid #000001;border-left:1px solid #000001;border-right:none;padding:0in">
			 <p align="CENTER"><font face="Arial, serif"><font style="font-size:8pt" size="1"><b>&nbsp;&nbsp;Travel Date</b></font></font></p>
			</td>

			<td style="border-top:1px solid #000001;border-bottom:1px solid #000001;border-left:1px solid #000001;border-right:none;padding:0in">
			  <p align="CENTER"><font face="Arial, serif"><font style="font-size:8pt" size="1"><b>Base Fare (in Rs.)</b></font></font></p>
			</td>

			<td style="border-top:1px solid #000001;border-bottom:1px solid #000001;border-left:1px solid #000001;border-right:none;padding:0in">
			  <p align="CENTER"><font face="Arial, serif"><font style="font-size:8pt" size="1"><b>Taxes (in Rs.)</b></font></font></p>
			</td>
		
			<td style="border-top:1px solid #000001;border-bottom:1px solid #000001;border-left:1px solid #000001;border-right:none;padding:0in">
			  <p align="CENTER"><font face="Arial, serif"><font style="font-size:8pt" size="1"><b>&nbsp;Admin charges  (in Rs.)</b></font></font></p>
			</td>

			<td style="border-top:1px solid #000001;border-bottom:1px solid #000001;border-left:1px solid #000001;border-right:1px solid #000001;padding:0in">
			  <p align="CENTER"><font face="Arial, serif"><font style="font-size:8pt" size="1"><b>Amount (in Rs.) &nbsp;&nbsp;</b></font></font></p>
			</td>
			</tr>
	   </tbody>';

//}
   
 
	include_once("conn.php");
	include("numtochar.php");
	$num2word=new numtowords($_REQUEST['invoiceamount']);

	$prg = new phpReportGenerator();
    $prg->width = "100%";
	$prg->cellpad = "0";
	$prg->cellspace = "0";
	$prg->border = "0";
	$prg->header_color = "#666666";
	$prg->header_textcolor="#FFFFFF";
	$prg->body_alignment = "right";
	$prg->body_color = "#CCCCCC";
	$prg->body_textcolor = "#800022";
	$prg->surrounded = '1';

  $custid=$_REQUEST['custid'];
  $invoicenumber=$_REQUEST['invoicenumber'];
  
  $sqladdr = "select address from customermast where custid =  '".$custid."'";
  
  $clientaddr = mysql_query($sqladdr);
  
   
 $sqlb=" SELECT p.`pax name` paxname, p.sector, concat( date_format(p.`Travel Date`,'%d/%m'), ' ', case when p.`Return Date` is null then '' else date_format(p.`Return Date`,'%d/%m') end)   traveldate, p.basic, p.tax, p.admincharges, p.amount,case when t.debitamt > 0 then 'D' when t.creditamt > 0 then 'C' end creditordebit
FROM transactionmast t
JOIN transactiondetails p ON t.trnid = p.tranid
WHERE custid =PARAM_CUST_ID and invoicenumber = PARAM_Invoice_NUM";
	
	$sqlb=str_replace('PARAM_CUST_ID',$custid,$sqlb);
	$sqlb=str_replace('PARAM_Invoice_NUM',$invoicenumber,$sqlb);
	
	$res = mysql_query($sqlb);
	$prg->mysql_resource = $res;
	$prg->title = "Test Table";
	$emailbody = $prg->generateReport($message);
	
	
	$footer= '<table cellpadding="0" cellspacing="0" width="730">
		<colgroup>
        <col width="418">
		<col width="50">
		<col width="1">
		<col width="105">
		</colgroup><tbody><tr>
			<td colspan="4" style="border-top:0px solid #000001;border-bottom:1px solid #000001;border-left:1px solid #000001;border-right:none;padding:0in" width="648">
				<p colspan="2" style="margin-bottom:0in">
				    <font face="Arial, serif"><font style="font-size:8pt" size="1"><b>&nbsp;Amount in words: </b></font></font>
					<font face="Arial, serif"><font style="font-size:8pt" size="1">&nbsp;';
					
					$footer.=$num2word->flushData().'</font></font> 
				</p>
			 </td>';

	
		$footer.='<!--<td style="border-top:1px solid #000001;border-bottom:1px solid #000001;border-left:none;border-right:none;padding:0in">
		         <p colspan="2" style="margin-bottom:0in" align="RIGHT"><font face="Arial, serif"><font style="font-size:8pt" size="1">&nbsp;&nbsp;Rs.   </font></font></p>
			 </td>
			<td style="border-top:1px solid #000001;border-bottom:1px solid #000001;border-left:none;border-right:none;padding:0in" valign="TOP" width="0"> <p><br> </p>
			</td>-->
			<td align="center" style="border-top:0px solid #000001;border-bottom:1px solid #000001;border-left:none;border-right:1px solid #000001;padding:0in" width="99">
			<p colspan="2" style="margin-bottom:0in" align="LEFT"><font face="Arial, serif"><font style="font-size:8pt" size="1"><b>Rs.&nbsp;&nbsp; '.$prg->outstanding_amt.'</b>&nbsp;&nbsp;</font></font></p>
			</td>
		</tr>
	</tbody>
  </table>
 </td>
</tr>
</tbody>
</table>

<div>
 
<p><font face="Arial, serif"><font style="font-size:11pt" size="1"><br><b>Terms &amp; Conditions:</b></font></font></p>
<p><font face="Arial, serif"><font style="font-size:11pt" size="1"><b>Cheque: </b>
<FONT SIZE=4 STYLE="font-size: 9pt">All Cheques / Demand Drafts in payment of bills must be crossed &quot;A/C Payee Only&quot;</font><br>
<FONT SIZE=4 STYLE="font-size: 9pt">and drawn in favour of <b> Shree Communications.</b></font></p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font face="Arial, serif" color = "red" style="font-size:11pt" size="2"><b>for Shree Communications</b></font></p>   
 
<font face="Arial, serif" style="font-size:11pt" size="1"><b>Note: </b></font>
<FONT SIZE=4 STYLE="font-size: 9pt">Service Tax exemption vide Notification No.6/2005-ST Dated 01/03/2005 </font></p>
<!--
<br>
<font face="Arial, serif" color = "red" style="font-size:11pt" size="2"><b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for Shree Communications &nbsp;&nbsp;</b></font> -->
<!--<br> -->
<p><FONT SIZE=4 STYLE="font-size: 9pt">&nbsp;This is a computer generated invoice,
   hence does not require Signature.<font  style="font-size:11pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Authorised Signatory &nbsp;&nbsp;</font></font></p>
</div>

</body>
</html>';

echo $footer;
  $finalecho=$emailbody.$footer;
include_once('phpToPDF.php') ;
$reportname = 'invoice_report_'.$_REQUEST['invoicenumber'].'.pdf';
phptopdf_html($finalecho,'pdf/',$reportname);
echo "<br><a href='pdf/".$reportname."'>Download PDF</a>";

if($send ==0)
 {
 
	$emailcc = 'manish@shreecomm.com';
	$custemail =$_REQUEST['custemail'];

	echo 
	'
	<form action="#" method="post" name="form" >

		<input name="flag" type="hidden" value="1">

		<p>To: <input name="emailto" type="text" value="'.$custemail.'"></p>
		CC: <input name="emailcc" type="text" value="'.$emailcc.'"><br>
		
		<input name="reportname" type="hidden" value="'.'pdf/'.$reportname.'">
		<input name="custdesc" type="hidden" value="'.$_REQUEST['custdesc'].'">
		<input name="reporttype" type="hidden" value="'.$_REQUEST['reporttype'].'">
		<input name="submit" type="submit" value="Send Email" class="bt">
	</form>
	';
}
	
	// email send 
	if($send==1)
	{
	
	$backupfile=$_REQUEST['reportname'];	
	
$invoiceno = explode("_", $backupfile);
$invoicenoonly = explode(".",$invoiceno[2]);

$emailto=$_REQUEST['emailto'];
$emailcc=$_REQUEST['emailcc'];

$torecipients = explode(",", $emailto);
$ccrecipients = explode(",", $emailcc);

$custdesc=$_REQUEST['custdesc'];
$emailfrom='manish@shreecomm.com';
//define the receiver of the email
//$to = $custemail;
//define the subject of the email
if($_REQUEST['reporttype']=="Invoice")
	$subject = 'Invoice';
if($_REQUEST['reporttype']=="CreditNote")
	$subject = 'Credit Note';
	

	
	$bodymatter="<br>Dear Customer,<br>
	<br>Thank you for choosing Shree Communications.<br>";

if($_REQUEST['reporttype']=="Invoice")
{	$bodymatter.= '<br>For your convenience, we have included a copy of your invoice.<br>';
	$bodymatter.= '<br>If you have any issues about your invoice,you can contact our support staff.<br>';
    $bodymatter.= '<br>We request you to kindly click on the below link for online payment options<br>';
	$bodymatter.= '<br>http://shreecomm.com/paynow.php<br>';
}
if($_REQUEST['reporttype']=="CreditNote")
{	$bodymatter.= '<br>For your convenience, we have included a copy of your credit note.<br>';
	$bodymatter.= '<br>If you have any issues about your credit note,you can contact our support staff.<br>';
}

$bodymatter.="<br>Warm Regards<br>
(Shree Communications Support Team)<br>
SHREE COMMUNICATIONS<br>
Shop no .2/5| Ganesh Darshan | Next to R-mall |L.B.S marg | Mulund W| Mumbai-400080<br>
MS,India Call :  022-21649516 | 8097915484 | 9819336100 | 8097920321<br>
Email : info@shreecomm.com | agents@shreecomm.com |  holidays@shreecomm.com<br>
<br>Help the environment - please don't print this email unless you really need to!<br>

<br>Please feel free to contact us for any further clarifications and queries.<br>";



require 'PHPMailerAutoload.php';

//Create a new PHPMailer instance
$mail = new PHPMailer;
$mail->setFrom( $emailfrom, 'Shree Communications');

foreach($torecipients as $email)
	$mail->addAddress( $email, "");
	
foreach($ccrecipients as $email )
	$mail->addCC($email,"");
$mail->Subject = $subject;

$mail->msgHTML($bodymatter);
$mail->addAttachment('pdf/'.$reportname);

ob_get_clean();
if (!$mail->send()) {
    echo "Mailer Error: " . $mail->ErrorInfo;
} else {
    echo "Message sent!";
}

//copy current buffer contents into $message variable and delete current output buffer



//if the message is sent successfully print "Mail sent". Otherwise print "Mail failed"
//echo $mail_sent ? 'Report sent to customer email '. $emailto : "Mail failed";

	}	

?>